package cp3;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class RequestInfoServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 如果post与get的请求处理操作一样 则完成一个操作即可
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setCharacterEncoding("utf-8"); // 设置编码
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter out = resp.getWriter(); // 获取输出对象

        //请求内容的编码
        String characterEncoding = req.getCharacterEncoding();
        String authType = req.getAuthType();
        // 项目的根路径
        String contextPath = req.getContextPath();
        // http请求方式
        String method = req.getMethod();
        // 路径信息
        String pathInfo = req.getPathInfo();
        String pathTranslated = req.getPathTranslated();
        // 查询参数字符串
        String queryString = req.getQueryString();
        String requestedSessionId = req.getRequestedSessionId();
        // 访问路径
        String requestURI = req.getRequestURI();
        // 完整的url访问路径
        String requestURL = req.getRequestURL().toString();
        // servlet的路径
        String servletPath = req.getServletPath();
        // 服务器的相关信息
        String localAddress = req.getLocalAddr();
        String localName = req.getLocalName();
        int localPort = req.getLocalPort();
        // 客户端的相关西悉尼
        String remoteUser = req.getRemoteUser();
        String remoteAddress = req.getRemoteAddr();
        String remoteHost = req.getRemoteHost();
        int remotePort = req.getRemotePort();
        // http的协议
        String protocol = req.getProtocol();
        String scheme = req.getScheme();

        out.println("characterEncoding:" + characterEncoding + "<br>");
        out.println("requestedSessionId:" + requestedSessionId + "<br>");
        out.println("authType:" + authType + "<br>");
        out.println("contextPath:" + contextPath + "<br>");
        out.println("method:" + method + "<br>");
        out.println("pathInfo:" + pathInfo + "<br>");
        out.println("pathTranslated:" + pathTranslated + "<br>");
        out.println("queryString:" + queryString + "<br>");
        out.println("requestURI:" + requestURI + "<br>");
        out.println("requestURL:" + requestURL + "<br>");
        out.println("servletPath:" + servletPath + "<br>");
        out.println("localAddress:" + localAddress + "<br>");
        out.println("localName:" + localName + "<br>");
        out.println("localPort:" + localPort + "<br>");
        out.println("protocol:" + protocol + "<br>");
        out.println("remoteUser:" + remoteUser + "<br>");
        out.println("remoteAddress:" + remoteAddress + "<br>");
        out.println("remoteHost:" + remoteHost + "<br>");
        out.println("remotePort:" + remotePort + "<br>");
        out.println("scheme:" + scheme + "<br>");
    }
}
